package mobileann.mafamily.utils;

import mobileann.mafamily.act.main.FS;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class UIUtils {
	public static int one2one(int px) {
		return px;
	}

	public static int dip2px(float dip) {
		int px = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		px = (int) ((float) dip * dm.density);
		dm = null;
		return px;
	}

	public static int px2dip(float px) {
		int dip = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		dip = (int) ((float) px / dm.density);
		dm = null;
		return dip;
	}

	public static int sp2px(float sp) {
		int px = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		px = (int) ((float) sp * dm.scaledDensity);
		dm = null;

		return px;
	}

	public static int px2sp(float px) {
		int dip = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		dip = (int) ((float) px / dm.scaledDensity);
		dm = null;
		return dip;
	}

	public static int currentScreenMode() {
		int md = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		md = dm.densityDpi;
		dm = null;
		return md;
	}

	public static float currentScreenModeDensity() {
		float md = 0.0f;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		md = dm.density;
		dm = null;
		return md;
	}

	public static int currentScreenX() {
		int md = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		md = dm.widthPixels;
		dm = null;
		return md;
	}

	public static int currentScreenY() {
		int md = 0;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wMgr.getDefaultDisplay().getMetrics(dm);
		md = dm.heightPixels;
		dm = null;
		return md;
	}
	
	public static DisplayMetrics currentDisplayMetrics() {
	    DisplayMetrics dm = new DisplayMetrics();
        WindowManager wMgr = (WindowManager) FS.getInstance().getSystemService(Context.WINDOW_SERVICE);
        wMgr.getDefaultDisplay().getMetrics(dm);
        return dm;
	}
}
